<%-- 
    Document   : distribuye
    Created on : Oct 12, 2012, 1:44:37 PM
    Author     : Jah
--%>

<%@page import="tickets.Privilege"%>
<%@page import="tickets.Controlador"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Distribuidor</title>
    </head>
    <body>
        <%
            Object ouser = session.getAttribute("user1");
            Object opass = session.getAttribute("password");
            String user, pass;

            if (ouser != null) {
                user = (String) ouser;
                pass = (String) opass;
            } else {
                user = request.getParameter("user");
                pass = request.getParameter("pass");
                session.setAttribute("user1", user);
                session.setAttribute("password", pass);
            }
            Controlador c = new Controlador();
            boolean valid = c.login(user, pass);
            if (valid) {
                Privilege privilegio=c.user.getPrivilege();
                session.setAttribute("privilegio", privilegio);
                if(privilegio==Privilege.supervisor){
                    response.sendRedirect("supervisor.jsp");
                }else if (privilegio==Privilege.empleado){
                    response.sendRedirect("empleado.jsp");
                }else{
                    // TODO: Error garrafal
                }
            } else {
                // TODO: Enviar error a index
                response.sendRedirect("index.jsp");
            }
        %>
    </body>
</html>
